package com.hkts.naturalgas.organizational.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.organizational.entity.HontRole;
import com.hkts.naturalgas.organizational.mapper.HontRoleMapper;
import com.hkts.naturalgas.organizational.service.IHontRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yck
 * @since 2021-04-06
 */
@Service
@Transactional
public class HontRoleServiceImpl extends ServiceImpl<HontRoleMapper, HontRole> implements IHontRoleService {


@Autowired
private HontRoleMapper hontRoleMapper;

@Override
public IPage<HontRole> selectPage(Page<HontRole> page, HontRole hontRole){
        QueryWrapper<HontRole> query = Wrappers.query();
        QueryWrapper<HontRole> entityWrapper = getEntityWrapper(query, hontRole);
        return hontRoleMapper.selectPage(page, entityWrapper);
        }




@Override
public List<HontRole> selectList(HontRole hontRole){
        QueryWrapper<HontRole> query = Wrappers.query();
        QueryWrapper<HontRole> entityWrapper = getEntityWrapper(query, hontRole);
        return hontRoleMapper.selectList(entityWrapper);
        }

/**
 *  公共查询条件
 * @param entityWrapper
 * @return
 */
public QueryWrapper<HontRole> getEntityWrapper(QueryWrapper<HontRole> entityWrapper,HontRole hontRole){
        //条件拼接
                /*if(StringUtils.isNotBlank(hontRole.getDefaultRole())){
                entityWrapper.like(HontRole.DEFAULT_ROLE,hontRole.getDefaultRole());
                }
                if(StringUtils.isNotBlank(hontRole.getDataType())){
                entityWrapper.like(HontRole.DATA_TYPE,hontRole.getDataType());
                }*/
                if(StringUtils.isNotBlank(hontRole.getDescription())){
                entityWrapper.like(HontRole.DESCRIPTION,hontRole.getDescription());
                }
                /*if(StringUtils.isNotBlank(hontRole.getCreateTime())){
                entityWrapper.like(HontRole.CREATE_TIME,hontRole.getCreateTime());
                }
                if(StringUtils.isNotBlank(hontRole.getUpdateTime())){
                entityWrapper.like(HontRole.UPDATE_TIME,hontRole.getUpdateTime());
                }*/
                if(StringUtils.isNotBlank(hontRole.getCreateBy())){
                entityWrapper.like(HontRole.CREATE_BY,hontRole.getCreateBy());
                }
//                if(StringUtils.isNotBlank(hontRole.getDelFlag())){
//                entityWrapper.like(HontRole.DEL_FLAG,hontRole.getDelFlag());
//                }
                if(StringUtils.isNotBlank(hontRole.getUpdateBy())){
                entityWrapper.like(HontRole.UPDATE_BY,hontRole.getUpdateBy());
                }
                /*if(StringUtils.isNotBlank(hontRole.getLevel())){
                entityWrapper.like(HontRole.LEVEL,hontRole.getLevel());
                }*/
                if(StringUtils.isNotBlank(hontRole.getName())){
                entityWrapper.like(HontRole.NAME,hontRole.getName());
                }
                if(StringUtils.isNotBlank(hontRole.getRoleName())){
                entityWrapper.like(HontRole.ROLE_NAME,hontRole.getRoleName());
                }
        return entityWrapper;
        }
        }
